<template>
  <div class="exchange">
    <BackNavigation v-bind:title-info="titleInfo"/>
    <div class="exchange-container">
      <div class="img-container">
        <img v-bind:src="commodityInfo.img" alt="">
      </div>
      <div class="info-container">
        <p>{{ commodityInfo.names }}</p>
        <p>{{ commodityInfo.score + ' 积分' }}</p>
        <p>{{ '¥' + commodityInfo.price }}</p>
        <p>运费：包邮</p>
      </div>
      <div class="img-info-container">
        <div>
          <img src="../../assets/img/mine_exchange_detail_icon.png" alt="">
          <p>商品详情</p>
        </div>
        <img v-for="imageItem in commodityInfo.img_all" v-lazy="imageItem.img">
        <img v-if="commodityInfo.explain" v-lazy="commodityInfo.explain.img">
      </div>
    </div>
    <input class="exchange-btn" type="button" v-bind:disabled="!getBtnStatus"
           v-bind:value="getBtnStatus ? '积分兑换' : '积分不足'"
           v-on:click.prevent="exchangeClick">
  </div>
</template>

<script>
  import * as recommend from 'api/recommend'
  import BackNavigation from './navigation.vue'

  export default {
    name: 'exchange',
    components: {
      BackNavigation
    },
    data () {
      return {
        titleInfo: {
          leftTitle: '返回',
          title: '积分兑换',
          rightTitle: ''
        },
        commodityInfo: {}
      }
    },
    computed: {
      getBtnStatus () {
        return (parseInt(this.commodityInfo.score) <= this.$store.state.usrScore)
      }
    },
    methods: {
      exchangeClick () {
        this.$router.push({
          path: '/exchange_order',
          query: {
            commodityScore: this.commodityInfo.score,
            commodityId: this.commodityInfo.Id
          }
        })
      }
    },
    activated () {
      recommend.get_exchange_commodity_info().then(resault => {
        console.log(123)
        if (resault.status === 200) {
          this.commodityInfo = resault.data.data[0]
        }
        console.log(resault.data)
      }).catch(resault => {
        console.log(resault)
      })
    }
  }
</script>

<style lang="scss">
  div.exchange {
    position: relative;
    height: auto;
    width: 100%;
    background-color: white;

    >div.exchange-container {
      position: relative;
      margin-top: 44px;
      margin-bottom: 44px;
      height: auto;
      width: 100%;
      /*background-color: red;*/

      >div.img-container {
        height: auto;
        width: 100%;

        >img {
          max-width: 100%;
          height: auto;
        }
      }

      >div.info-container {
        height: 60px;
        width: 100%;
        background-color: rgb(243, 243, 243);

        >p {
          /*display: inline-block;*/
          /*background-color: greenyellow;*/
          float: left;
          height: 30px;
          width: auto;
          line-height: 30px;
          font-size: 14px;
          color: rgb(66, 66, 66);
          font-weight: bold;
        }

        >p:first-child {
          margin-left: 15px;
          position: absolute;
          font-size: 16px;
          font-weight: bold;
        }

        >p:nth-child(2) {
          margin-top: 30px;
          margin-left: 15px;
          float: left;
          font-size: 16px;
          color: rgb(27, 162, 232);
          font-weight: bold;
        }

        >p:nth-child(3) {
          margin-top: 30px;
          margin-left: 15px;
          float: left;
          color: rgb(133, 133, 133);
          font-size: 14px;
          font-weight: bold;
        }

        >p:last-child {
          margin-top: 30px;
          margin-right: 15px;
          float: right;
          color: rgb(133, 133, 133);
          font-size: 14px;
          font-weight: bold;
        }
      }

      >div.img-info-container {
        height: auto;
        width: 100%;

        >div {
          padding-top: 10px;
          overflow: hidden;
          height: 30px;
          width: 100%;

          >img {
            margin-left: 15px;
            float: left;
            padding: 2px 0 2px 0;
            max-width: 20px;
            height: 20px;
          }

          >p {
            float: left;
            margin-left: 5px;
            height: 20px;
            line-height: 20px;
            color: rgb(66, 66, 66);
            font-size: 16px;
            font-weight: bold;
          }
        }

        >img {
          max-width: 100%;
          height: auto;
        }
      }
    }

    >input.exchange-btn {
      position: fixed;
      left: 0;
      z-index: 6;
      float: left;
      height: 44px;
      width: 100%;
      bottom: 0;
      padding: 0 10px 0 10px;
      text-align: center;
      font-size: 14px;
      background-color: rgb(27, 162, 232);
      border-radius: 0;
      color: white;
      border: 0 solid orange;
      -webkit-appearance: none;  /*去掉苹果的默认UI来渲染按钮*/
    }

    >input.exchange-btn:disabled {
      color: rgb(66, 66, 66);
      background-color: rgb(233, 233, 233);
      -webkit-appearance: none;
      border: 0 solid rgb(133, 133, 133);
      opacity: 1.0;
    }
  }
</style>
